<template>
  <div class="global">
    <form class="config-form">
      <div class="form-group">
        <label for="service-url">大模型服务地址</label>
        <input type="text" id="service-url" v-model="llmServiceUrl" placeholder="https://api.example.com/v1" required>
      </div>

      <div class="form-group">
        <label for="api-key">大模型密钥</label>
        <input type="text" id="api-key" v-model="llmApiKey" placeholder="请输入API密钥">
      </div>

      <div class="form-group">
        <label for="api-key">模型名称</label>
        <input type="text" id="api-key" v-model="modelName" placeholder="请输入模型名称">
      </div>

      <!-- <div class="form-group">
        <label for="prompt-label">系统提示词</label>
        <textarea id="prompt" v-model="prompt" placeholder="请输入系统提示词" />
      </div> -->

      <div class="button-group">
        <button type="submit" class="save-btn" @click="saveConfig()">保存</button>
        <!-- <button type="submit" class="test-btn">测试</button> -->
        <!-- <button type="button" class="cancel-btn" @click="hideTP()">取消</button> -->
      </div>
    </form>
  </div>
</template>

<script type="text/javascript">
import { onMounted } from 'vue'
import axios from 'axios'
import taskPane from './js/llm_config_tp.js'
import fileutils from './js/fileutil.js'
export default {
  name: 'LlmConfigTp',
  data() {
    return {
      llmServiceUrl: 'https://api.deepseek.com/v1',
      llmApiKey: 'sk-5e9b169a9b1e4c17bbe43feedf5a4dd5',
      configPath: 'llm.config',
      prompt: '你是一个文档编辑助手,现在用户选定了部分内容需要你进行优化，请从通顺、逻辑等方面进行优化改写，直接返回优化后的内容。',
      modelName: 'deepseek-reasoner'
    }
  },
  mounted() {
    this.llmServiceUrl = fileutils.getItem(fileutils.LLM_BASE_URL_KEY)
    this.llmApiKey = fileutils.getItem(fileutils.LLM_APIKEY_KEY)
    this.modelName = fileutils.getItem(fileutils.LLM_MODEL_NAME)
  },
  methods: {
    saveConfig() {
      fileutils.setItem(fileutils.LLM_BASE_URL_KEY, this.llmServiceUrl);
      fileutils.setItem(fileutils.LLM_APIKEY_KEY, this.llmApiKey);
      fileutils.setItem(fileutils.LLM_MODEL_NAME, this.modelName);
      wps.alert("大模型配置保存成功")
    },
    hideTP() {
      taskPane.hideTaskPane();
    },
    hideDiglog() {
      taskPane.hideTaskPane();
    },
    onDocNameClick() {
      this.docName = taskPane.onbuttonclick('getDocName')
    },
    onOpenWeb() {
      taskPane.onbuttonclick('openWeb', this.DemoSpan)
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

body {
  padding: 2rem;
  background-color: #f5f5f5;
}

.config-form {
  max-width: 800px;
  margin: 0 auto;
  background: white;
  padding: 2rem;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.form-group {
  margin-bottom: 1.5rem;
}

label {
  display: block;
  margin-bottom: 0.5rem;
  color: #333;
  font-weight: 500;
}

input,
textarea {
  width: 100%;
  padding: 0.8rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 14px;
  transition: border-color 0.3s ease;
}

textarea {
  height: 380px;
}

input:focus {
  outline: none;
  border-color: #2196F3;
  box-shadow: 0 0 0 2px rgba(33, 150, 243, 0.1);
}

.button-group {
  display: flex;
  gap: 1rem;
  margin-top: 2rem;
}

button {
  flex: 1;
  padding: 0.8rem 1.5rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s ease;
}

.save-btn {
  background-color: #2196F3;
  color: white;
}

.cancel-btn {
  background-color: #f5f5f5;
  color: #666;
}

.test-btn {
  background-color: #4CAF50;
  color: white;
}

button:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}
</style>
